<template>
  <div class="aftOrder-wrapper">
    <div class="aftOrder-hd">
      <div class="aftOrder-hd-item" @click="changeHd(0)" :class="curIndex==0?'sel-item':''">选择商品</div>
      <div class="aftOrder-hd-item" @click="changeHd(1)" :class="curIndex==1?'sel-item':''">售后查看</div>
    </div>
    <div class="aftOrder-bd">
        <div v-if="curIndex == 0">
            <div v-for="(item,index) in detail.orderItems" :key="index" class="aftOrder-chosGoods">
                <Card :imgSrc="item.modelImageUrl" :name="item.productTitle">
                    <div class="item-desc">
                        <span class="item-desc-info">{{item.modelName}} {{item.modelSize}}</span>
                    </div>
                    <div class="item-price">
                        <span class="price-icon">￥</span>
                        <span class="item-price-num">{{item.totalPrice}}</span>
                    </div>
                    <div @click="linkTo('/shouhouDetail?id='+item.id+'&code='+item.orderCode+'&freight='+detail.freight)" class="aftSer-btn" v-if="item.refundStatus == 'NORMAL'">申请售后</div>
                </Card>
            </div>
            <div
                v-if="!detail.orderItems.length"
                class="no-data"
            >
                当前列表为空~
            </div>
        </div>
      <div v-else-if="curIndex == 1" class="aftOrder-aftOrders">
        <div class="aftOrder-item" v-for="(item,index) in refundList" :key="index">
          <div class="item-hd">
            <span class="aftOrder-code">售后编号：{{item.refundCode}}</span>
            <span class="aftOrder-date">{{item.gmtCreated}}</span>
          </div>
          <div class="item-card">
            <Card :imgSrc="item.productOrderItemsDTO.modelImageUrl" :name="item.productOrderItemsDTO.productTitle">
               <div class="item-desc">
                <span class="item-desc-info">{{item.productOrderItemsDTO.modelName}} {{item.productOrderItemsDTO.modelSize}}</span>
              </div>
              <div class="item-price">
                <span class="price-icon">￥</span>
                <span class="item-price-num">{{item.productOrderItemsDTO.modelSalePrice}}</span>
              </div>
            </Card>
          </div>
          <div class="item-ft">
            <div class="aftOrder-status">
              <span class="aftOder-satus-content"> 状态：<span class="aftOrder-status-detail">{{auditStatusList.filter( audit => {return audit.value == item.refundStatus})[0].label}}</span></span>
              <!--<div @click="showCancelDialog" v-if="item.refundStatus=='WAIT_AUDIT'" class="aftOrder-btn">取消售后</div>-->
              <div v-if="item.refundStatus=='FAILURE'" class="aftOrder-btn" @click="$router.push('/shouhouDetail?id='+item.orderItemId+'&code='+item.orderCode)">重新申请</div>
              <!--<div @click="handleDelOrder(item.orderCode)" v-else-if="item.refundStatus=='SUCCESS'" class="aftOrder-btn">删除订单</div>-->
            </div>
            <div class="aftOrder-reason" v-show="item.reason">
              原因：
              <span  class="aftOrder-reason-detail">{{item.reason}}</span>
            </div>
          </div>
        </div>
        <div
            v-if="!refundList.length"
            class="no-data"
        >
            当前列表为空~
        </div>
      </div>
    </div>
    <div v-transfer-dom>
      <confirm v-model="delDialog"
        :hide-on-blur="true"
        confirm-text="取消"
        cancel-text="确认"
        @on-cancel="confirmDel"
        @on-confirm="delDialog = false">
        <p class='dialog-content'>确认删除售后订单?</p>
      </confirm>
    </div>
  </div>  
</template>

<script>
	import CONSTANT from "../../../wechat/static/constant/urlconstant";
	import common from "../../../wechat/static/common/common";
import Card from "@/components/common/Goods-card.vue";
const testimg1 = require("../../images/test.png");
import {Confirm,TransferDomDirective as TransferDom } from 'vux';
export default {
  directives: {
    TransferDom
  },
  data() {
    return {
      cancelDialog:false,
      delDialog:false,
      curIndex: 0,
      orderList: [
        {
          code: "12345678",
          time: "2018/06/30  10:34",
          status: "审核通过",
          reason: "",
          name:
            "宝得适britax百变骑士汽车儿童安全座椅isofix9个月+12岁很长很长很长很长",
          img: testimg1,
          desc: {
            color: "黄色",
            length: "两米"
          },
          price: "158.00"
        },
        {
          code: "12345678",
          time: "2018/06/30  10:34",
          status: "审核不通过",
          reason: "该商品不属于退款范围内",
          name:
            "宝得适britax百变骑士汽车儿童安全座椅isofix9个月+12岁很长很长很长很长",
          img: testimg1,
          desc: {
            color: "黄色",
            length: "两米"
          },
          price: "158.00"
        },
        {
          code: "12345678",
          time: "2018/06/30  10:34",
          status: "待审核",
          reason: "",
          name:
            "宝得适britax百变骑士汽车儿童安全座椅isofix9个月+12岁很长很长很长很长",
          img: testimg1,
          desc: {
            color: "黄色",
            length: "两米"
          },
          price: "158.00"
        },
        {
          code: "12345678",
          time: "2018/06/30  10:34",
          status: "退货处理中",
          reason: "",
          name:
            "宝得适britax百变骑士汽车儿童安全座椅isofix9个月+12岁很长很长很长很长",
          img: testimg1,
          desc: {
            color: "黄色",
            length: "两米"
          },
          price: "158.00"
        },
        {
          code: "12345678",
          time: "2018/06/30  10:34",
          status: "已完成",
          reason: "",
          name:
            "宝得适britax百变骑士汽车儿童安全座椅isofix9个月+12岁很长很长很长很长",
          img: testimg1,
          desc: {
            color: "黄色",
            length: "两米"
          },
          price: "158.00"
        }
      ],
        detail: {
          orderItems: []
        },
        auditStatusList: [{
	        label: "待审核",
	        value: "WAIT_AUDIT"
        },{
	        label: "处理中",
	        value: "IN_PROCESS"
        },{
	        label: "售后成功",
	        value: "SUCCESS"
        },{
	        label: "售后失败",
	        value: "FAILURE"
        },{
	        label: "默认状态",
	        value: "NORMAL"
        }],
        pageIndex: 1,
        pageSize: 10,
        refundList: [],
        orderCode: ""
    };
  },
  components: {
    Card,
    Confirm,
  },
    mounted() {
  	    if (this.$route.query.index) {
  	    	this.curIndex = 1
          this.getList()
        }
        if (this.$route.query.code) {
	        this.getDetail()
        }
    },
  methods:{
	  getDetail() {
		  let url = CONSTANT.ORDER.ORDERDETAIL
		  common.get(url, this.$route.query.code, (res) => {
			  if (res.code == 200) {
				  this.detail = res.data.bussData
			  }
		  })
	  },
      getList() {
        this.$vux.loading.show({
              text: "加载中"
          });
	      let url = CONSTANT.REFUND.LIST
	      common.post(url, {pageSize: this.pageSize, pageIndex: this.pageIndex}, (res) => {
          this.$vux.loading.hide();
          if (res.code == 200) {
			      this.refundList = res.data.bussData
		      }
	      })
      },
    linkTo(link){
      this.$router.push(link);
     },
     changeHd(index) {
      this.curIndex = index;
      if (index == 1) {
	      this.getList()
      }else{
        this.getDetail()
      }
    },
	  handleDelOrder(orderCode){
    	this.orderCode = orderCode
		  this.delDialog = true;
	  },
	  confirmDel() {
	  	let url = CONSTANT.ORDER.ORDERDEL
          common.get(url, this.orderCode, (res) => {
          	if (res.code ==200) {
          		this.$vux.toast.show({
                    type: "success",
                    text: "删除成功"
                })
                this.getList()
            }
          })
      },
    showCancelDialog(){
      this.cancelDialog=true;
    },

  }
};
</script>

<style lang="less">
.aftOrder-wrapper {
  .no-data {
        text-align: center;
        font-size: 0.28rem;
        font-family: PingFang-SC-Bold;
        color: rgba(153, 153, 153, 1);
        margin-top: 40%;
    }
  .aftOrder-hd {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 0.88rem;
    background-color: #f2f2f2;
    .aftOrder-hd-item {
      color: #999999;
      font-family: PingFang-SC-Medium;
      font-weight: 500;
      font-size: 0.28rem;
      width: 2.5rem;
      text-align: center;
    }
    .sel-item {
      line-height: 0.88rem;
      height: 100%;
      position: relative;
      font-size: 0.32rem;
      font-family: PingFang-SC-Bold;
      font-weight: bold;
      color: rgba(126, 86, 198, 1);
    }
    .sel-item:after {
      content: "";
      position: absolute;
      bottom: 0.08rem;
      left: 1.1rem;
      border-bottom: 0.06rem solid rgba(126, 86, 198, 1);
      width: 0.3rem;
      border-radius: 30%;
    }
  }
  .aftOrder-bd {
    .aftOrder-chosGoods {
      .card {
        margin-bottom: 0.2rem;
        /*padding-left: 0.2rem;*/

        .aftSer-btn {
          position: absolute;
          bottom: 0.3rem;
          right: 0.5rem;
          width: 1.88rem;
          height: 0.56rem;
          border: 0.02rem solid;
          border-color: linear-gradient(
              111deg,
              rgba(126, 86, 198, 1),
              rgba(98, 123, 230, 1)
            )
            2 2;
          border-radius: 0.28rem;
          text-align: center;
          font-size: 0.28rem;
          font-family: PingFang-SC-Medium;
          font-weight: 500;
          color: rgba(126, 86, 198, 1);
          line-height: 0.56rem;
        }
      }
    }
    .aftOrder-aftOrders {
      .aftOrder-item {
        background: #fff;
        margin-bottom: 0.2rem;
        .item-hd {
          padding: 0 0.3rem 0 0.2rem;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          align-items: center;
          height: 0.9rem;
          box-shadow: 0px -1px 0px 0px rgba(230, 230, 230, 1);
          border-bottom: 0.01rem solid rgba(207, 207, 207, 0.6);
            overflow: hidden;
            text-overflow: ellipsis;
            display: flex;
          .aftOrder-code {
            font-size: 0.3rem;
            font-family: PingFang-SC-Medium;
            font-weight: 500;
            color: rgba(51, 51, 51, 1);
              white-space: nowrap;
              flex: 1;
          }
          .aftOrder-date {
            font-size: 0.28rem;
            font-family: PingFang-SC-Medium;
            font-weight: 500;
            color: rgba(153, 153, 153, 1);
              white-space: nowrap;
              margin-left: 20px;
              overflow: hidden;
              text-overflow: ellipsis;
          }
        }
        .item-card {
          margin: 0 0rem 0 0.2rem;
          border-bottom: 0.01rem solid rgba(207, 207, 207, 0.6);
        }
        .item-ft{
          padding:0 0rem .2rem 0.2rem;
          .aftOrder-status{
            display: flex;
            flex-direction: row;
            justify-content: space-between;
            margin-top:.2rem;
            color:#666666;
            font-size: .3rem;
            .aftOrder-status-detail{
              color:#7C3EA3;
            }
            .aftOrder-btn{
              margin-right:.3rem;
              width:1.88rem;
              height:0.56rem;
              line-height:0.56rem;
              border: 0.02rem solid;
              border-color: linear-gradient(111deg, rgba(126, 86, 198, 1), rgba(98, 123, 230, 1)) 2 2;
              border-radius: 0.28rem;
              text-align: center;
              color:#7E56C6;
            }
          }
          .aftOrder-reason{
           margin-top:.2rem;
            color:#666666;
            font-size: .3rem;
            .aftOrder-reason-detail{
              color:#333333;
            }
          }
        }
      }
    }
  }
  .goods-content {
    .good-img {
      width: 2.32rem;
      height: 2.33rem;
      background-size: 100%;
    }
  }
  .goods-item-content {
    position: relative;
    z-index: 2;
    background: white;
    height: 2.32rem;
    padding: 0.21rem 0.23rem 0.2rem 0.21rem;
    overflow: hidden;
    text-overflow: ellipsis;
    .item-desc {
      .item-desc-info {
        font-size: 0.26rem;
        font-family: PingFang-SC-Light;
        color: rgba(158, 158, 158, 1);
        line-height: 0.5rem;
        margin-right: 0.2rem;
      }
    }
    .item-price {
      position: absolute;
      bottom: 0.15rem;
      color: rgba(126, 86, 198, 1);
      .item-price-num {
        font-size: 0.31rem;
        font-family: PingFang-SC-Light;
        line-height: 0.52rem;
      }
    }
  }
}
</style>
